package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.vo.ValueSkuJsonVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 10574
 * @description 针对表【spu_sale_attr(spu销售属性)】的数据库操作Service实现
 * @createDate 2022-11-29 17:33:22
 */
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
        implements SpuSaleAttrService {

    @Override
    public List<SpuSaleAttr> spuSaleAttrList(Long spuId) {
        List<SpuSaleAttr> saleAttrList = baseMapper.spuSaleAttrList(spuId);
        return saleAttrList;
    }

    @Override
    public List<SpuSaleAttr> getSpuSaleAttr(Long spuId, Long skuId) {
        List<SpuSaleAttr> saleAttrList = baseMapper.getSpuSaleAttr(spuId, skuId);
        return saleAttrList;
    }

    @Override
    public String getValuesSkuJson(Long spuId) {
        List<ValueSkuJsonVo> voList=baseMapper.getValuesSkuJson(spuId);
        Map<String, Long> map = voList.stream()
                .collect(Collectors.toMap((t) -> t.getValueJson(), t -> t.getSkuId()));
        String jsonString = JSON.toJSONString(map);
        return jsonString;
    }
}




